package com.maverick.guardianangel;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;



import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.os.Bundle;


public class WhatDoesThisSay extends Activity {
	private static final String TAG = "CameraDemo";
	  Preview preview; // <1>
	  Button buttonClick; // <2>
	  ProgressDialog dialog;
	    int increment = 14;
	    private TextView txt;  
	  
	  /** Called when the activity is first created. */
	  @Override
	  public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.wdoests);

	    preview = new Preview(this); // <3>
	    ((FrameLayout) findViewById(R.id.preview)).addView(preview); // <4>

	    buttonClick = (Button) findViewById(R.id.buttonClick);
	    buttonClick.setOnClickListener(new OnClickListener() {
	      public void onClick(View v) { // <5>
	        preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
	      }
	    });

	    Log.d(TAG, "onCreate'd");
	  }

	  // Called when shutter is opened
	  ShutterCallback shutterCallback = new ShutterCallback() { // <6>
	    public void onShutter() {
	      Log.d(TAG, "onShutter'd");
	    }
	  };

	  // Handles data for raw picture
	  PictureCallback rawCallback = new PictureCallback() { // <7>
	    public void onPictureTaken(byte[] data, Camera camera) {
	      Log.d(TAG, "onPictureTaken - raw");
	    }
	  };

	  // Handles data for jpeg picture
	  PictureCallback jpegCallback = new PictureCallback() { // <8>
	    public void onPictureTaken(byte[] data, Camera camera) {
	      FileOutputStream outStream = null;
	      try {
	        // Write to SD Card
	        outStream = new FileOutputStream(String.format("/sdcard/DCIM/100ANDRO/%d.jpg",
	            System.currentTimeMillis())); // <9>
	        outStream.write(data);
	        outStream.close();
	        Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
	      } catch (FileNotFoundException e) { // <10>
	        e.printStackTrace();
	      } catch (IOException e) {
	        e.printStackTrace();
	      } finally {
	      }
	      Log.d(TAG, "onPictureTaken - jpeg");
	    }
	  };
	  
	  public boolean onCreateOptionsMenu(Menu menu) {
	        MenuInflater inflater = getMenuInflater();
	        inflater.inflate(R.menu.send, menu);
	        return true;
	    }
	  
	  public boolean onOptionsItemSelected(MenuItem item) { 
		    switch (item.getItemId()) {
		        case R.id.item02:
		        	startSend();
		        case R.id.item01:     
		            //Toast.makeText(this, "You pressed Exit!", Toast.LENGTH_LONG).show();          
		            System.exit(0);                 
		            break;
		    }
		    return true;
		}
	  
	  private void startSend()
	  {
		  Intent intent = new Intent(this,ImageSending.class);
		    //intent.setClass(WhereAmI.this, TestProviderController.class);
		    startActivity(intent);
	  }
	  

	}

